package cc.togetherit.jcrawler.down;

import java.util.ArrayList;
import java.util.List;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

import cc.togetherit.jcrawler.proxy.HttpHead;



@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement
@XmlType(name = "downConfig", propOrder = {"type", "httpHeaders", "proxys"})
public class DownEngineConfig {

    private int type;

    @XmlElement(required = true)
    private List<HttpHead> httpHeaders = new ArrayList<HttpHead>();;
    @XmlElement(required = true)
    private String[] proxys;

    public String[] getProxys() {
        return proxys;
    }

    public void setProxys(String[] proxys) {
        this.proxys = proxys;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }


    public List<HttpHead> getHttpHeaders() {
        return httpHeaders;
    }

    public String[][] getHttpHeaderArray() {
        String headers[][] = new String[httpHeaders.size()][2];
        String headerss[];
        for (int i = 0; i < httpHeaders.size(); i++) {
            headerss = new String[2];
            headerss[0] = httpHeaders.get(i).getKey();
            headerss[1] = httpHeaders.get(i).getValue();
            headers[i] = headerss;
        }
        return headers;
    }

    public void setHttpHeaders(List<HttpHead> httpHeaders) {
        this.httpHeaders = httpHeaders;
    }

    public void addHttphead(HttpHead httpHead) {
        httpHeaders.add(httpHead);
    }

    public void defaultConfig() {
        HttpHead head = new HttpHead("User-Agent", "Mozilla/5.0 (Windows NT 5.1; rv:14.0) Gecko/20100101 Firefox/14.0");
        List<HttpHead> list = new ArrayList<HttpHead>();
        list.add(head);
        this.setHttpHeaders(list);
        this.setProxys(null);
        this.setType(1);

    }

}
